open Unix;;
open Bigarray;;



let mlMain n  m=
  Random.self_init();
  let vec1 =  Array1.create float32 c_layout n
  and vec2 =  Array1.create float32 c_layout n
  and vec3 =  Array1.create float32 c_layout n
  and res2 = ref (Array1.create float32 c_layout n)
  and vec4 = Array.make n 0.0 
  and vec5 = Array.make n 0.0
  and vec6 = Array.make n 0.0
  and res1 = ref (Array.make n 0.0) in
    (
      for i = 0 to (n-1) do	
	Array1.set vec1 i (Random.float 32.0);
	Array1.set vec2 i (Random.float 32.0);
	Array1.set vec3 i (Random.float 32.0);
	Array.set vec4 i (Random.float 32.0);
	Array.set vec5 i (Random.float 32.0);
	Array.set vec6 i (Random.float 32.0);
      done;
      
      Printf.printf "Bigarray generated\n";
      flush Pervasives.stdout;
      let t1 = Unix.times () in
	(
	  for i = 0 to m do 
	    (
	      for i = 0 to (n-1) do
		(
		  Array1.set !res2 i ( (Array1.get vec1 i)*.(Array1.get vec2 i)+.(Array1.get vec3 i));
		)
	      done;
	    )
	  done;
	  let t2 = Unix.times () in
	    (
	      for i = 0 to m do 
		(
		  for i = 0 to (n-1) do
		    (
		      !res1.(i)<- ( (vec4.(i))*.(vec5.(i))+.(vec6.(i)));
		    )
		  done;
		)
		done;
		  let t3 = Unix.times () in
		    (
		      
		      Printf.printf "Temps OCaml: %f\n" ((t2.tms_utime)-.(t1.tms_utime));
		      Printf.printf "Temps OCaml: %f\n" ((t3.tms_utime)-.(t2.tms_utime));
		      flush Pervasives.stdout;
		    )
	    )
	)
    )

    
;;



mlMain (int_of_string (Sys.argv.(1))) (int_of_string (Sys.argv.(2)));
;;
